package com.fx.util;

import com.alibaba.fastjson.JSONObject;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class JsonRowMapper implements RowMapper<JSONObject> {

    public JSONObject mapRow(ResultSet resultSet, int i) throws SQLException {
        int columnCount = resultSet.getMetaData().getColumnCount();
        JSONObject jsonObject = new JSONObject();
        for (int j = 1; j <= columnCount; j++) {
            String key = resultSet.getMetaData().getColumnName(j);
            String value = resultSet.getString(j);
            jsonObject.put(key, value);
        }

        return jsonObject;
    }
}
